Skip to content

Fix/handling hierarchy#32

Open
TDannhauer wants to merge 7 commits into
FRAMEWORK_6_0from
fix/handling_hierarchy
Open

Fix/handling hierarchy#32
TDannhauer wants to merge 7 commits into
FRAMEWORK_6_0from
fix/handling_hierarchy

Conversation

@TDannhauer
Copy link
Copy Markdown
Contributor

Request FolderSync when hierarchy is invalid during PING

Summary

When the server invalidates the folder hierarchy synckey in the device sync cache (for example after task list or calendar folder changes in a groupware app), clients were only forced to run FolderSync on the next SYNC request. PING could continue for minutes without telling the device to refresh its folder hierarchy, so new or removed folders did not appear until the user triggered an unrelated sync (e.g. editing a task).

This change aligns PING with the existing SYNC behaviour (ActiveSync 12.1+): if haveHierarchy() is false, return FolderSync required instead of waiting in pollForChanges().

Changes

lib/Horde/ActiveSync/Request/Ping.php

Before entering the PING wait loop, if the device protocol version is ≥ 12.1 and the sync cache has no valid hierarchy synckey (!haveHierarchy()), respond immediately with PING status 7 (STATUS_FOLDERSYNCREQD) and stop processing.

This mirrors the check already present at the start of Horde_ActiveSync_Request_Sync for STATUS_FOLDERSYNC_REQUIRED (12).

lib/Horde/ActiveSync/Collections.php

At the beginning of pollForChanges(), if the device is ≥ 12.1 and haveHierarchy() is false, return COLLECTION_ERR_FOLDERSYNC_REQUIRED so any PING path that reaches the poll loop also terminates with FolderSync required (same outcome as the explicit handling in Ping.php).

Why version ≥ 12.1

The hierarchy synckey in Horde_ActiveSync_SyncCache and the associated status codes are part of the ActiveSync 12.1 folder hierarchy model. Older clients use a different folder sync flow; Horde already gates the SYNC-side check on VERSION_TWELVEONE ('12.1'). Both Ping.php and Collections.php use the same guard so clients ≤ 12.0 are unchanged.

Behaviour notes

  • Invalidating hierarchy means setting the cache hierarchy value to empty/'0' (see SyncCache::__isset / haveHierarchy()), not clearing the folder cache.
  • PING status 7 and COLLECTION_ERR_FOLDERSYNC_REQUIRED were already handled in Ping.php; this change ensures the condition is detected before a long heartbeat wait.
  • A cache timestamp bump alone (COLLECTION_ERR_STALE) only ends PING early; it does not instruct the client to run FolderSync.

Test plan

  • Device on ActiveSync 12.1+ (e.g. iOS Mail/Tasks): invalidate hierarchy on server (demux task lists or similar), confirm next PING returns FolderSync required (status 7) in server log.
  • Confirm FolderSync runs and delivers FolderHierarchy:Add / Remove as appropriate.
  • Confirm normal PING/SYNC still works when hierarchy synckey is valid.
  • No change expected for clients < 12.1 (guard not applied).

Related work

Companion changes in Nag (separate PR): web-side task list create/delete updates sync_lists and invalidates hierarchy without pruning device folder cache before FolderSync.

@TDannhauer TDannhauer requested a review from ralflang May 23, 2026 17:10
Updated hierarchy check and added folder resync logic for collections. Enhanced pingable collections handling and added logging for missing folder cache entries.
Refactor PING request handling to improve collection loading logic and status codes.
@ralflang
Copy link
Copy Markdown
Member

ralflang commented May 24, 2026

This PR is part of a companion pair: horde/nag#25 invalidates hierarchy (sets hierarchy = '0') when task lists change on the web; #32 makes PING
detect that invalidation and return FolderSync-required immediately instead of waiting through the heartbeat. Neither works without the other. They
should ship together.

On #32 itself: the '0' sentinel convention introduced here isn't documented in SyncCache! The restorePingableCollectionsFromCache() method may re-enable
collections the user intentionally excluded from sync. The switch from status 132 to status 7 for "no pingable collections" on v14+ changes client behavior in a way worth detailing in a long docblock.

Also not ideal: No test coverage for the new logic.

@ralflang ralflang mentioned this pull request May 24, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants